package com.umeng.p7qimokaoshi.Molder;

import com.example.myhttp.client.HttpClient;
import com.example.mymvp.view.callback.BaseModelCallback;
import com.example.mymvp.view.model.BaseModel;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.umeng.p7qimokaoshi.Bean.DoemList;
import com.umeng.p7qimokaoshi.Bean.Dome;
import com.umeng.p7qimokaoshi.CallBack.HttpCallBack;
import com.umeng.p7qimokaoshi.Prensenter.MainPrensenter;

import java.util.HashMap;
import java.util.List;

public class MainMolder implements BaseModel {

    public void getData(BaseModelCallback baseModelCallback, LifecycleProvider lifecleProvider) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("cityid","1");
        map.put("operaVersion","5.1.1");
        new HttpClient.Builder()
                .setBaseUrl("https://api.zhuge.com/")
                .setApiUrl("home/v1/Appindex/showBanner")
                .setParamser(map)
                .post()
                .setLifecycleProvider(lifecleProvider)
                .build()
                .excute(new HttpCallBack<List<Dome.ListBean>>() {
                    @Override
                    protected void error(String error, int code) {
                        baseModelCallback.onError(error, code);
                    }

                    @Override
                    protected void onSucess(List<Dome.ListBean> list) {
                        baseModelCallback.onSucess(list);
                    }

                    @Override
                    public List<Dome.ListBean> convert(JsonElement jsonElement) {
                        Dome dome = new Gson().fromJson(jsonElement, Dome.class);
                        return dome.getList();
                    }
                });
    }

    public void getData1(BaseModelCallback baseModelCallback, LifecycleProvider lifecleProvider) {
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("cityid","1");
        map1.put("operaVersion","5.1.1");
        new HttpClient.Builder()
                .setBaseUrl("https://api.zhuge.com/")
                .setApiUrl("home/v1/Appindex/showTopic")
                .setParamser(map1)
                .post()
                .setLifecycleProvider(lifecleProvider)
                .build()
                .excute(new HttpCallBack<List<DoemList.ListBean>>() {
                    @Override
                    protected void error(String error, int code) {
                        baseModelCallback.onError(error, code);
                    }

                    @Override
                    protected void onSucess(List<DoemList.ListBean> listBeans) {
                        baseModelCallback.onRecSucess(listBeans);
                    }

                    @Override
                    public List<DoemList.ListBean> convert(JsonElement jsonElement) {
                        DoemList doemList = new Gson().fromJson(jsonElement, DoemList.class);
                        return doemList.getList();
                    }
                });

    }
}
